package cn.mesmile.interview.juc;

/**
 * @author zb
 * @date 2021/11/18 11:33
 * @Description
 */
public class DeadLock {

    private static Object a = new Object();

    private static Object b = new Object();

    public static void main(String[] args) {
        // 死锁
        Thread threadOne = new Thread(() -> {
            synchronized (a) {
                try {
                    // 让出cpu使用权，不会释放锁
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b) {
                    System.out.println("a里获取到b");
                }
            }
        },"one");

        Thread threadTwo = new Thread(() -> {
            synchronized (b) {
                try {
                    // 让出cpu使用权，不会释放锁
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (a) {
                    System.out.println("b里获取到a");
                }
            }
        },"two");

        threadOne.start();
        threadTwo.start();

    }
}
